package top.program.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.program.user.entity.User;
import top.program.user.service.UserService;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/index")
    public String user(){
        User user = new User();
        user.setMobile("123456");
        user.setRealName("laowang");
        user.setUsername("laowang");
        user.setPassword("123456");
        User user2 = new User();
        user2.setId(1L);
        user2.setMobile("123456");
        user2.setRealName("laowang");
        user2.setUsername("laowang");
        user2.setPassword("123456");
        return "/login";
    }

    @RequestMapping("/home")
    public String home(){

        return "home";
    }

    /**
     *@Author xcl
     *@Date 2017/10/14 18:04
     *@Description 获取用户信息
     */
    @RequestMapping("/userinfo")
    @ResponseBody
    public User getUser(HttpSession session){
        User user = (User) session.getAttribute("userinfo");
        return user;
    }

    /**
     *@Author xcl
     *@Date 2017/10/14 22:08
     *@Description 登出系统
     */
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "login";
    }
}
